<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用BFC避免外边距重叠</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .container {
            border: 1px solid red;
        }

        .cube {
            width: 100px;
            height: 100px;
            background: blue;
            float: left;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="cube"></div>
    </div>
</body>

</html>